home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Celestin Apprentice 5
/
Apprentice-Release5.iso
/
Source Code
/
Libraries
/
SAT 2.3.8
/
Demos
/
StepPlatform Demo ƒ
/
sMovPlatform.p
< prev
next >
Wrap
Text File
|
1995-09-03
|
3KB
|
115 lines
(* Platform sprite, moveable version, not faceless *)
(* *)
unit sMovPlatform;
interface
uses
{$ifc UNDEFINED THINK_PASCAL}
Types, QuickDraw, Menus, Windows, TextEdit, Fonts, Dialogs, Memory, {}
{$endc}
SAT, PlatformGlobals, sPlayerSprite;
procedure InitMovPlatform;
procedure SetupMovPlatform (me: SpritePtr);
implementation
const
MovPlatformSpeed = 2;
var
platFace: FacePtr;
procedure InitMovPlatform;
begin
platFace := SATGetFace(139);
end;
procedure HandleMovPlatform (me: SpritePtr);
begin
me^.position.v := me^.position.v + me^.speed.v;
if (me^.position.v < MovPlatP(me^.appPtr)^.MinV) then
me^.speed.v := MovPlatformSpeed;
if (me^.position.v > MovPlatP(me^.appPtr)^.MaxV) then
me^.speed.v := -MovPlatformSpeed;
if (me^.speed.v = 0) then
begin
if (me^.position.v > (MovPlatP(me^.appPtr)^.MaxV - MovPlatP(me^.appPtr)^.MinV) div 2) then
me^.speed.v := -MovPlatformSpeed
else
me^.speed.v := MovPlatformSpeed;
end;
me^.layer := -me^.position.v;
end;
procedure HitMovPlatform (me: SpritePtr; him: PlSpritePtr);
var
mini, i, min: Integer;
diff: array[0..5] of Integer;
begin
if (him^.task = @HandlePlayerSprite) then
begin
diff[1] := -me^.hotRect2.top + (him^.hotRect2.bottom); (* (T)toB *)
diff[2] := -him^.hotRect2.top + (me^.hotRect2.bottom); (* (B)toT *)
diff[3] := -me^.hotRect2.left + (him^.hotRect2.right); (* LtoR *)
diff[4] := -him^.hotRect2.left + (me^.hotRect2.right); (* RtoL *)
mini := 0;
min := 10000;
for i := 1 to 4 do
if min > diff[i] then
begin
min := diff[i];
mini := i;
end;
case mini of
1: (*floor*)
begin
him^.action := Stand;
him^.position.v := him^.position.v - diff[1] + 2;
if (him^.speed.v > 0) then
him^.speed.v := 0;
him^.speed.h := 0;
end;
2: (* ceiling *)
begin
him^.position.v := him^.position.v + diff[2] + 1;
if (him^.speed.v < 0) then
him^.speed.v := -him^.speed.v;
end;
3: (*left*)
begin
him^.position.h := him^.position.h - diff[3] - 1;
if (him^.speed.h > 0) then
him^.speed.h := -him^.speed.h;
end;
4: (*right*)
begin
him^.position.h := him^.position.h + diff[4] + 1;
if (him^.speed.h < 0) then
him^.speed.h := -him^.speed.h;
end;
end; (* switch *)
end; (* if *)
end;
procedure SetupMovPlatform (me: SpritePtr);
var
r: Rect;
pol: PolyHandle;
begin
me^.speed.v := -MovPlatformSpeed + SATRand(2) * 2;
me^.face := platFace;
me^.appPtr := NewPtr(sizeof(MovPlatRec));
if me^.appPtr <> nil then
begin
MovPlatP(me^.appPtr)^.MaxV := me^.position.v;
MovPlatP(me^.appPtr)^.MinV := me^.kind;
end;
SetRect(me^.hotRect, 0, 3, 60, 20);
me^.task := @HandleMovPlatform;
me^.hitTask := @HitMovPlatform;
end;
end.